﻿package eu.liquify.ui {
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Rectangle;
	public class UIItem extends Sprite {
		//[Embed(systemFont="Segoe UI", mimeType="application/x-font", fontName="LabelFont", unicodeRange="U+0020-U+007E", embedAsCFF=false)]
		//[Embed(systemFont="Times New Roman", mimeType="application/x-font", fontName="LabelFont", unicodeRange="U+0020-U+007E", embedAsCFF=false)]
		//[Embed(systemFont="Tahoma", mimeType="application/x-font", fontName="LabelFont", embedAsCFF=false)]
		//[Embed(source="assets/DroidSans.ttf", mimeType="application/x-font", fontName="LabelFont", unicodeRange="U+0020-U+007E", embedAsCFF=false)] private var labelFont:String;
		//[Embed(source="assets/DroidSans-Bold.ttf", mimeType="application/x-font", fontName="LabelFont", fontWeight="bold", unicodeRange="U+0020-U+007E", embedAsCFF=false)] private var labelFontBold:String;
		[Embed(source="assets/DroidSans.ttf", mimeType="application/x-font", fontName="LabelFont", unicodeRange="U+0020-U+007E", embedAsCFF=false)] private var labelFont:String;
		[Embed(source="assets/DroidSans-Bold.ttf", mimeType="application/x-font", fontName="LabelFont", fontWeight="bold", unicodeRange="U+0020-U+007E", embedAsCFF=false)] private var labelFontBold:String;
		
		//public static const REPOSITION:String = "uiReposition";
		
		protected static const NULL_FUNCTION:Function = new Function();
		
		//public static var gridWidth:Number = 100;
		//public static var gridHeight:Number = 22;
		protected static var nextTabIndex:int = 0;
		
		//public var fitToGrid:Boolean = true;
		//public var fitToGrid:Boolean = false;
		
		//public var fixedSize:Boolean = false;
		public var fixedWidth:Boolean = true;
		public var fixedHeight:Boolean = true;
		
		private var _label:String = "";
		
		private var rect:Rectangle = new Rectangle();
		
		//public var debugSize:Boolean = true;
		private var _debugSize:Boolean = false;
		
		override public function get x():Number {
			return rect.x;
		}
		override public function set x(v:Number):void {
			rect.x = v;
			super.x = v;
		}
		override public function get y():Number {
			return rect.y;
		}
		override public function set y(v:Number):void {
			rect.y = v;
			super.y = v;
		}
		
		override public function get width():Number {
			return rect.width;
		}
		override public function set width(v:Number):void {
			rect.width = v;
			if (debugSize) updateDebugSize();
		}
		override public function get height():Number {
			return rect.height;
		}
		override public function set height(v:Number):void {
			rect.height = v;
			if (debugSize) updateDebugSize();
		}
		
		public function get fixedSize():Boolean {
			return fixedWidth && fixedHeight;
		}
		public function set fixedSize(v:Boolean):void {
			fixedWidth = fixedHeight = v;
		}
		
		public function get label():String { return _label; }
		
		public function set label(value:String):void {
			_label = value;
		}
		
		public function get debugSize():Boolean {
			return _debugSize;
		}
		
		public function set debugSize(value:Boolean):void {
			_debugSize = value;
			updateDebugSize();
		}
		
		
		public function UIItem(options:Object = null):void {
			applyOptions(options);
			if (debugSize) updateDebugSize();
		}
		
		public function resize():void {}
		
		/*
		public function serialize():String { return ""; }
		public function deserialize(s:String):void {}
		*/
		
		private function updateDebugSize():void {
			var g:Graphics = graphics;
			g.clear();
			if (!debugSize || !rect) return;
			g.beginFill(0xFF0000);
			g.drawRect(-1, -1, width+2, height+2);
			g.drawRect(0, 0, width, height);
			//g.drawRect(0, 0, width, height);
			//g.drawRect(1, 1, width-2, height-2);
			g.endFill();
		}
		
		protected function applyOptions(options:Object = null):void {
			if (options) {
				for (var p:String in options) {
					try {
						this[p] = options[p];
					} catch (e:ReferenceError) {
						throw new ArgumentError("There is no option/property with the name "+p+".");
					}
				}
			}
		}
		
	}
}